package org.wu.framework.authorization.platform.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.wu.framework.web.spring.EasyController;
import org.springframework.web.bind.annotation.*;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import jakarta.annotation.Resource;

import java.util.List;

import org.wu.framework.authorization.platform.domain.model.sys.permission.SysPermission;
import org.wu.framework.authorization.platform.application.command.sys.permission.SysPermissionRemoveCommand;
import org.wu.framework.authorization.platform.application.command.sys.permission.SysPermissionStoryCommand;
import org.wu.framework.authorization.platform.application.command.sys.permission.SysPermissionUpdateCommand;
import org.wu.framework.authorization.platform.application.command.sys.permission.SysPermissionQueryListCommand;
import org.wu.framework.authorization.platform.application.command.sys.permission.SysPermissionQueryOneCommand;
import org.wu.framework.authorization.platform.application.SysPermissionApplication;
import org.wu.framework.authorization.platform.application.dto.SysPermissionDTO;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.authorization.platform.application.command.sys.permission.SysPermissionExcelExport;
import org.wu.framework.authorization.platform.application.command.sys.permission.SysPermissionExcelImport;
import org.wu.framework.easy.excel.stereotype.RequestExcelBody;
import org.wu.framework.easy.excel.stereotype.EasyExcel;

/**
 * describe 系统权限
 *
 * @author Jia wei Wu
 * @date 2025/08/03 01:55 下午
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyController
 **/
@Tag(name = "系统权限提供者")
@EasyController("/sys/permission")
public class SysPermissionProvider {

    @Resource
    private SysPermissionApplication sysPermissionApplication;

    /**
     * describe 新增系统权限
     *
     * @param sysPermissionStoryCommand 新增系统权限
     * @return {@link Result<SysPermission>} 系统权限新增后领域对象
     * @author Jia wei Wu
     * @date 2025/08/03 01:55 下午
     **/

    @Operation(summary = "新增系统权限")
    @PostMapping("/story")
    public Result<SysPermission> story(@RequestBody SysPermissionStoryCommand sysPermissionStoryCommand) {
        return sysPermissionApplication.story(sysPermissionStoryCommand);
    }

    /**
     * describe 批量新增系统权限
     *
     * @param sysPermissionStoryCommandList 批量新增系统权限
     * @return {@link Result<List<SysPermission>>} 系统权限新增后领域对象集合
     * @author Jia wei Wu
     * @date 2025/08/03 01:55 下午
     **/

    @Operation(summary = "批量新增系统权限")
    @PostMapping("/batchStory")
    public Result<List<SysPermission>> batchStory(@RequestBody List<SysPermissionStoryCommand> sysPermissionStoryCommandList) {
        return sysPermissionApplication.batchStory(sysPermissionStoryCommandList);
    }

    /**
     * describe 更新系统权限
     *
     * @param sysPermissionUpdateCommand 更新系统权限
     * @return {@link Result<SysPermission>} 系统权限领域对象
     * @author Jia wei Wu
     * @date 2025/08/03 01:55 下午
     **/

    @Operation(summary = "更新系统权限")
    @PutMapping("/updateOne")
    public Result<SysPermission> updateOne(@RequestBody SysPermissionUpdateCommand sysPermissionUpdateCommand) {
        return sysPermissionApplication.updateOne(sysPermissionUpdateCommand);
    }

    /**
     * describe 查询单个系统权限
     *
     * @param sysPermissionQueryOneCommand 查询单个系统权限
     * @return {@link Result<SysPermissionDTO>} 系统权限DTO对象
     * @author Jia wei Wu
     * @date 2025/08/03 01:55 下午
     **/

    @Operation(summary = "查询单个系统权限")
    @GetMapping("/findOne")
    public Result<SysPermissionDTO> findOne(@ModelAttribute SysPermissionQueryOneCommand sysPermissionQueryOneCommand) {
        return sysPermissionApplication.findOne(sysPermissionQueryOneCommand);
    }

    /**
     * describe 查询多个系统权限
     *
     * @param sysPermissionQueryListCommand 查询多个系统权限
     * @return {@link Result<List<SysPermissionDTO>>} 系统权限DTO对象
     * @author Jia wei Wu
     * @date 2025/08/03 01:55 下午
     **/

    @Operation(summary = "查询多个系统权限")
    @GetMapping("/findList")
    public Result<List<SysPermissionDTO>> findList(@ModelAttribute SysPermissionQueryListCommand sysPermissionQueryListCommand) {
        return sysPermissionApplication.findList(sysPermissionQueryListCommand);
    }

    /**
     * describe 扫描系统权限
     *
     * @return {@link Result<List<SysPermissionDTO>>} 系统权限DTO对象
     * @author Jia wei Wu
     * @date 2025/08/03 01:55 下午
     **/

    @Operation(summary = "扫描系统权限")
    @GetMapping("/findScanPermission")
    public Result<List<SysPermissionDTO>> findScanPermission() {
        return sysPermissionApplication.findScanPermission();
    }

    /**
     * describe 分页查询多个系统权限
     *
     * @param sysPermissionQueryListCommand 分页查询多个系统权限
     * @return {@link Result<LazyPage<SysPermissionDTO>>} 分页系统权限DTO对象
     * @author Jia wei Wu
     * @date 2025/08/03 01:55 下午
     **/

    @Operation(summary = "分页查询多个系统权限")
    @GetMapping("/findPage")
    public Result<LazyPage<SysPermissionDTO>> findPage(@Parameter(description = "分页大小") @RequestParam(defaultValue = "10", value = "size") int size,
                                                       @Parameter(description = "当前页数") @RequestParam(defaultValue = "1", value = "current") int current, @ModelAttribute SysPermissionQueryListCommand sysPermissionQueryListCommand) {
        return sysPermissionApplication.findPage(size, current, sysPermissionQueryListCommand);
    }

    /**
     * describe 删除系统权限
     *
     * @param sysPermissionRemoveCommand 删除系统权限
     * @return {@link Result<SysPermission>} 系统权限
     * @author Jia wei Wu
     * @date 2025/08/03 01:55 下午
     **/

    @Operation(summary = "删除系统权限")
    @DeleteMapping("/remove")
    public Result<SysPermission> remove(@ModelAttribute SysPermissionRemoveCommand sysPermissionRemoveCommand) {
        return sysPermissionApplication.remove(sysPermissionRemoveCommand);
    }

    /**
     * describe 导出系统权限
     *
     * @param sysPermissionQueryListCommand 导出系统权限
     * @return {@link List<SysPermissionExcelExport>} 系统权限
     * @author Jia wei Wu
     * @date 2025/08/03 01:55 下午
     **/

    @EasyExcel(fileName = "导出系统权限数据")
    @Operation(summary = "导出系统权限")
    @GetMapping("/exportExcel")
    public List<SysPermissionExcelExport> exportExcel(@ModelAttribute SysPermissionQueryListCommand sysPermissionQueryListCommand) {
        return sysPermissionApplication.exportExcel(sysPermissionQueryListCommand);
    }

    /**
     * describe 导出模版系统权限
     *
     * @return {@link Result<List<SysPermissionExcelExport>>} 系统权限
     * @author Jia wei Wu
     * @date 2025/08/03 01:55 下午
     **/

    @EasyExcel(fileName = "导出系统权限模版数据")
    @Operation(summary = "导出系统权限模版")
    @GetMapping("/exportTemplateExcel")
    public List<SysPermissionExcelExport> exportTemplateExcel() {
        return List.of(new SysPermissionExcelExport());
    }

    /**
     * describe 导入系统权限
     *
     * @param sysPermissionExcelImportList 导入系统权限
     * @return {@link Result<SysPermissionExcelImport>} 系统权限
     * @author Jia wei Wu
     * @date 2025/08/03 01:55 下午
     **/

    @Operation(summary = "导入系统权限")
    @PostMapping("/importExcel")
    public Result<List<SysPermissionExcelImport>> importExcel(@RequestExcelBody("multipartFile") List<SysPermissionExcelImport> sysPermissionExcelImportList) {
        return sysPermissionApplication.importExcel(sysPermissionExcelImportList);
    }
}